package com.butterfly.hotkey.dashboard.biz.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.butterfly.hotkey.dashboard.biz.service.UserService;
import com.butterfly.hotkey.dashboard.biz.vo.user.LoginRepVO;
import com.butterfly.hotkey.dashboard.biz.vo.user.LoginReqVO;
import com.butterfly.hotkey.common.result.Result;
import com.butterfly.hotkey.dashboard.biz.vo.user.UserVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户
 *
 * @author butterfly
 * @since 2024-10-24
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result<LoginRepVO> login(@RequestBody LoginReqVO reqVO) {
        LoginRepVO repVO = userService.login(reqVO);
        return Result.success(repVO);
    }

    /**
     * 登出
     */
    @PostMapping("/logout")
    public Result<Boolean> logout() {
        StpUtil.logout();
        return Result.success();
    }

    /**
     * 查询个人信息
     */
    @GetMapping("/detail")
    public Result<UserVO> getUserDetail() {
        long loginId = StpUtil.getLoginIdAsLong();
        UserVO repVO = userService.getUserDetail(loginId);
        return Result.success(repVO);
    }

    /**
     * 编辑个人信息
     */
    @PostMapping("/edit")
    public Result<Boolean> edit() {
        return Result.success();
    }

    /**
     * 修改密码
     */
    @PostMapping("/update-password")
    public Result<Boolean> updatePassword() {
        return Result.success();
    }

}

